package MyGO;

import MyGO.Data.GlobalData;
import MyGO.Form.TrackForm;
import MyGO.service.*;
import MyGO.service.impl.*;
import MyGO.utils.FileUtils.FileIO;

import java.io.IOException;
import java.util.List;

public class ShutdownHook extends Thread{
    private ITrackFormService trackFormService = new TrackFormServiceImpl();
    private IAmountService amountService = new AmountServiceImpl();
    private ICheackProService cheackProService = new CheckProServiceImpl();
    private IDoctorService doctorService = new DoctorServiceImpl();
    private IMedicineService medicineService = new MedicineServiceImpl();

    @Override
    public void run() {
        // 在退出前保存数据
        try {
            FileIO.writeObjectAsJsonFile(TrackForm.count, "count.json");


            FileIO.writeObjectAsJsonFile(trackFormService.selectAllTrackForm(), "TrackForm.json");


            FileIO.writeObjectAsJsonFile(amountService.getAllAmount(), "Amount.json");


            FileIO.writeObjectAsJsonFile(cheackProService.selectAllCheckPro(), "CheckPro.json");
            FileIO.writeObjectAsJsonFile(cheackProService.getAllCheckPro(), "CheckProMap.json");


            FileIO.writeObjectAsJsonFile(doctorService.selevtAllDoctor(), "Doctor.json");
            FileIO.writeObjectAsJsonFile(doctorService.IDToDoctor(), "DoctorMap.json");


            FileIO.writeObjectAsJsonFile(medicineService.getMedicineList(), "Medicine.json");
            FileIO.writeObjectAsJsonFile(medicineService.getMedicineMap(), "MedicineMap.json");

            System.out.println("Data saved before exit.");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
